// import Vue from "vue";
export default {
    install(Vue){
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> 36b4eaab32b312f7ed99e774a924af1f2e73a966
        // 获取session，以方便获取token等其它用户登录信息
        Vue.prototype.$getSession = function (){
            return JSON.parse(sessionStorage.getItem('userdata'))
        }
        // 路由跳转
        Vue.prototype.$toRouter = function (router){
            this.$router.push(router)
        }
        // 日期转换，能够根据发送的时间输出为 刚刚、XX分钟前、XX小时前、XX天前
<<<<<<< HEAD

=======
=======
        Vue.prototype.$getSession = function (){
            return JSON.parse(sessionStorage.getItem('userdata'))
        }
        Vue.prototype.$toRouter = function (router){
            this.$router.push(router)
        }
>>>>>>> 47b53261c8e91e7ca39280b9dc0f230d5a19dd33
>>>>>>> 36b4eaab32b312f7ed99e774a924af1f2e73a966
        Vue.prototype.$transDate = function (datastamp){
            let distance = new Date()-datastamp*1000
            if(distance/1000 < 60){
                return '刚刚'
            }else if(distance/1000/60 >= 1&&distance/1000/60 < 60){
                return (distance/1000/60).toFixed(0) + '分钟前'
            }else if(distance/1000/60/60 >= 1&&distance/1000/60/60 < 24){
                return (distance/1000/60/60).toFixed(0) + '小时前'
            }else if(distance/1000/60/60/24>=1){
                return (distance/1000/60/60/24).toFixed(0) + '天前'
            }
        }
<<<<<<< HEAD
=======
<<<<<<< HEAD
>>>>>>> 36b4eaab32b312f7ed99e774a924af1f2e73a966
        // 判断字符串是否为JSON字符串
        Vue.prototype.$isJson = function (str){
            if (typeof str == 'string') {
                try {
                    var obj=JSON.parse(str);
                    if(typeof obj == 'object' && obj ){
                        return true;
                    }else{
                        return false;
                    }

                } catch(e) {
                    return false;
                }
            }
        }
        // 删除session，用于会话失效退出登录
        Vue.prototype.$deleteSession = function (){
            sessionStorage.removeItem('userdata')
        }
<<<<<<< HEAD
=======
=======
>>>>>>> 47b53261c8e91e7ca39280b9dc0f230d5a19dd33
>>>>>>> 36b4eaab32b312f7ed99e774a924af1f2e73a966
    }
}